package run
 
import (
	"nightowl/route"
	. "nightowl/controller"
	. "nightowl/svc/run"
	. "nightowl/model"
	"github.com/gin-gonic/gin"
	"net/http"
	// "time"
	// "fmt"
    // "gopkg.in/yaml.v2"
)
type DeliveryController struct {
	
}
var index int
func (run DeliveryController) GetDetail(c *gin.Context){ //,httpMethod string
	index = index + 1
	d := GetDeliveryInfo()
    
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"message": "SUCCESS",
		"data": d,
		"url": c.Request.URL,
	}) 
}
func (run DeliveryController) Start(c *gin.Context){ //,httpMethod string
	d := GetDeliveryInfo()
	go DeliveryRunSvc.Start(&d)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"message": "ok",
		"data": DeliveryRunSvc.Status,
	})
}
func (run DeliveryController) Run(c *gin.Context){ 
	var delivery Delivery
    
    // 绑定 JSON 数据到结构体
    if err := c.ShouldBindJSON(&delivery); err != nil {
        c.JSON(http.StatusOK, gin.H{"code":500, "message": err.Error()})
        return
    }
	go DeliveryRunSvc.Start(&delivery)
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"message": "ok",
		"data": DeliveryRunSvc.Status,
	})
}
//这里每个controller执行init方法都要注册自动路由
func init() {
	c := &DeliveryController{}
	restInfo := &RestInfo{
		BasePath: "/api/v1/delivery",
	}
	route.Register(*restInfo, c)
}